<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>项目进度</title>
<meta name="decorator" content="default" />
<link href="${ctxStatic}/product.css" type="text/css" rel="stylesheet" />
<link href="${ctxStatic}/font-awesome/css/font-awesome.min.css"
	type="text/css" rel="stylesheet" />
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a id="btn" href="${ctx}/pro/taskGroup/list?project.id=${e.id}">任务组列表</a></li>
		<shiro:hasPermission name="pro:taskGroup:create"><li><a href="javascript:void(0);" onclick="groupForm('','${e.id}');">任务组添加</a></li></shiro:hasPermission>
		<shiro:hasPermission name="pro:proLog:view">
			<li><a href="${ctx}/pro/proLog/list?project.id=${e.id}">项目日志</a>
			</li>
         </shiro:hasPermission>
		<li class="active"><a href="${ctx}/pro/project/ganttViewData?id=${e.id}">项目进度</a></li>
		<shiro:hasPermission name="pro:taskGroup:import">
			<li><a href="${ctx}/pro/taskGroup/previewList?project.id=${proLog.project.id}">任务导入</a>
			</li>
         </shiro:hasPermission>
	</ul>
	<div id="ganttChart"></div>
	<input id="projectId" type="hidden" value="${e.id}"/>
	<br />
	<br />
	<div id="eventMessage"></div>
<script type="text/javascript">
	/* var ganttData = [ {
		id : 1,
		name : "Feature 1",
		series : [ {
			name : "Planned",
			start : new Date(2010, 00, 01),
			end : new Date(2010, 00, 03)
		}, {
			name : "Actual",
			start : new Date(2010, 00, 02),
			end : new Date(2010, 00, 05),
			color : "#f0f0f0"
		} ]
	}, {
		id : 2,
		name : "Feature 2",
		series : [ {
			name : "Planned",
			start : new Date(2010, 00, 05),
			end : new Date(2010, 00, 20)
		}, {
			name : "Actual",
			start : new Date(2010, 00, 06),
			end : new Date(2010, 00, 17),
			color : "#f0f0f0"
		}, {
			name : "Projected",
			start : new Date(2010, 00, 06),
			end : new Date(2010, 00, 17),
			color : "#e0e0e0"
		} ]
	}, {
		id : 3,
		name : "Feature 3",
		series : [ {
			name : "Planned",
			start : new Date(2010, 00, 11),
			end : new Date(2010, 01, 03)
		}, {
			name : "Actual",
			start : new Date(2010, 00, 15),
			end : new Date(2010, 01, 03),
			color : "#f0f0f0"
		} ]
	}, {
		id : 4,
		name : "Feature 4",
		series : [ {
			name : "Planned",
			start : new Date(2010, 01, 01),
			end : new Date(2010, 01, 03)
		}, {
			name : "Actual",
			start : new Date(2010, 01, 01),
			end : new Date(2010, 01, 05),
			color : "#f0f0f0"
		} ]
	}, {
		id : 5,
		name : "Feature 5",
		series : [ {
			name : "Planned",
			start : new Date(2010, 02, 01),
			end : new Date(2010, 03, 20)
		}, {
			name : "Actual",
			start : new Date(2010, 02, 01),
			end : new Date(2010, 03, 26),
			color : "#f0f0f0"
		} ]
	}, {
		id : 6,
		name : "Feature 6",
		series : [ {
			name : "Planned",
			start : new Date(2010, 00, 05),
			end : new Date(2010, 00, 20)
		}, {
			name : "Actual",
			start : new Date(2010, 00, 06),
			end : new Date(2010, 00, 17),
			color : "#f0f0f0"
		}, {
			name : "Projected",
			start : new Date(2010, 00, 06),
			end : new Date(2010, 00, 20),
			color : "#e0e0e0"
		} ]
	}, {
		id : 7,
		name : "Feature 7",
		series : [ {
			name : "Planned",
			start : new Date(2010, 00, 11),
			end : new Date(2010, 01, 03)
		} ]
	}, {
		id : 8,
		name : "Feature 8",
		series : [ {
			name : "Planned",
			start : new Date(2010, 01, 01),
			end : new Date(2010, 01, 03)
		}, {
			name : "Actual",
			start : new Date(2010, 01, 01),
			end : new Date(2010, 01, 05),
			color : "#f0f0f0"
		} ]
	} ]; */
	function ganttView(data){
		var gantt = eval('('+data+')');
		var ganttData = [];
		for(var i = 0;i < gantt.length;i++){
			var taskGroup = {};
			taskGroup.name = gantt[i].name;
			taskGroup.id = gantt[i].id;
			var taskList = [];
			for(var j = 0;j < gantt[i].tasks.length;j++){
				var task = {};
				task.name= gantt[i].tasks[j].name;
				task.id= gantt[i].tasks[j].id;
				task.start= gantt[i].tasks[j].startTime;
				task.end= gantt[i].tasks[j].endTime;
				task.flag= gantt[i].tasks[j].flag;
				if(task.flag == "1"){
					task.color="#e0e0e0";
				}
				taskList.push(task);
			}
			taskGroup.series = taskList;
			ganttData.push(taskGroup);
		}
		$("#ganttChart").ganttView(
				{
					data : ganttData,
					slideWidth : 900,
					behavior : {
						onClick : function(data) {
							/* var msg = "You clicked on an event: { start: "
									+ data.start.toString("M/d/yyyy")
									+ ", end: " + data.end.toString("M/d/yyyy")
									+ ",id: "+data.id+"}";
							$("#eventMessage").text(msg); */
							taskFormDisable(data.id);
						},
						onResize : function(data) {
							/* var msg = "You resized an event: { start: "
									+ data.start.toString("M/d/yyyy")
									+ ", end: " + data.end.toString("M/d/yyyy")
									+ ",id: "+data.id+" }";
							$("#eventMessage").text(msg); */
							if(data.flag == 0){
								updateFromGantt(data.id,data.start.toString("yyyy-MM-dd"),data.end.toString("yyyy-MM-dd"));
							}
						},
						onDrag : function(data) {
							/* var msg = "You dragged an event: { start: "
									+ data.start.toString("M/d/yyyy")
									+ ", end: " + data.end.toString("M/d/yyyy")
									+ ",id: "+data.id+" }";
							$("#eventMessage").text(msg); */
							if(data.flag == 0){
								updateFromGantt(data.id,data.start.toString("yyyy-MM-dd"),data.end.toString("yyyy-MM-dd"));
							}
						}
					}
				});
	}
	function updateFromGantt(id,startTime,endTime){
		var url = "${ctx}/pro/projectTask/updateFromGantt";
		$.ajax({
            type: 'POST',
            url : url,
            async:false,
            data: {id:id,startTime:startTime,endTime:endTime},             //获取表单数据
            success : function(data) {
            		if(data == "success"){
		            	alertx("修改成功");
            		}else{
		            	alertx("无权限");
            		}
            },
            error : function(data){
            	alertx("无权限");
            }
        });
	}
	function taskFormDisable(taskId){
		var url = "${ctx}/pro/projectTask/formDisable?id="+taskId;
		top.$.jBox.open("iframe:"+url, "任务详情",810,$(top.document).height()-120,{
            buttons:{"关闭":true}, bottomText:"任务详情",submit:function(v, h, f){
                var code;
                if (v=="ok"){
                	// 执行保存
                    //loading('正在提交，请稍等...');
                	h.find("iframe")[0].contentWindow.submitForm();
                	location.reload();
                    return false;
                }
            }, loaded:function(h){
                $(".jbox-content", top.document).css("overflow-y","hidden");
            }
        });
	}
	$(function() {
		var url = "${ctx}/pro/project/ganttViewJson";
        $.ajax({
            type: 'POST',
            url : url,
            async:false,
            data: {projectId:$("#projectId").val()},             //获取表单数据
            success : function(data) {
            		ganttView(data);
                    /* window.parent.page();                                     //调用父窗体方法，当关闭子窗体刷新父窗体
                    window.parent.window.jBox.close(); */            //关闭子窗体
            },
            error : function(data){
            	alertx("无权限");
            }
        });
	});
</script>
</body>
</html>